package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
)

func home(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
func user(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}

func readBodyOnce(w http.ResponseWriter, r *http.Request) {
	body, err := io.ReadAll(r.Body)
	fmt.Fprintf(w, "First time read body: %s \n", body)

	if err != nil {
		fmt.Fprintf(w, "Read body failed \n")
	}

	body, err = io.ReadAll(r.Body)
	fmt.Fprintf(w, "First time read body: %s \n", body)

	if err != nil {
		fmt.Fprintf(w, "Read body failed \n")
	}

}

func main() {
	http.HandleFunc("/body/once", readBodyOnce)
	log.Fatal(http.ListenAndServe(":8080", nil))
}
